Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Why does function "checkpassword" makes nothing on click?

I have a problem guys. As a beginner, I am trying to check the length of password and return the result, but it doesn't work. after clicking button, it does nothing. What am I doing wrong?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
function checkpassword(){
    var pas=document.getElementByName(passcode).value;
    var x=pas.length;
    if(x<8){
        document.getElementById(message).innerHTML="Error 404!";
   }
   else{
    document.getElementById(message).innerHTML="It's acceptable"
   }
}
</script>
<body>
   
    <input type="password" name="passcode" placeholder="Enter password to check">
    <input type="submit" value="submit" onclick="checkpassword()">

<p id="message"></p>
</body>
</html>
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

@'Felix Kling' and @'Daniel A. White have given some hints in the comments because you will have to pass the names and ids as strings. But another issue is that .getElementByName() is not a function. You can try this (note that I have used .getElementsByName (plural) and referenced the zero-ith index:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<script>
function checkpassword(){
    var pas=document.getElementsByName('passcode')[0].value;
    var x=pas.length;
    if(x<8){
        document.getElementById("message").innerHTML="Error 404!";
   }
   else{
    document.getElementById("message").innerHTML="It's acceptable"
   }
}
</script>
<body>
   
    <input type="password" name="passcode" placeholder="Enter password to check">
    <input type="submit" value="submit" onclick="checkpassword()">

<p id="message"></p>
</body>
</html>
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda